package com.lijiajia.cloud.common.core.rest;

import com.lijiajia.cloud.common.core.business.BaseStatus;
import com.lijiajia.cloud.common.core.business.BusinessStatus;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 接口统一返回对象
 *
 * @author lijiajia
 * @since 2019-04-05
 */
@Data
@Builder
@Accessors(chain = true)
public class Result implements Serializable {
    private String code;
    private String msg;
    private Object data;

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(BusinessStatus status) {
        this.code = status.code();
        this.msg = status.msg();
    }

    public Result(BusinessStatus status, Object data) {
        this.code = status.code();
        this.msg = status.msg();
        this.data = data;
    }

    public static Result success() {
        return new Result(BaseStatus.SUCCESS);
    }

    public static Result success(Object data) {
        return new Result(BaseStatus.SUCCESS, data);
    }

    public static Result error() {
        return new Result(BaseStatus.ERROR);
    }

    public static Result build(BusinessStatus status) {
        return new Result(status);
    }

    public static Result build(BusinessStatus status, Object data) {
        return new Result(status, data);
    }

    public static Result build(String code, String msg) {
        return new Result(code, msg);
    }

    public static Result build(String code, String msg, Object data) {
        return new Result(code, msg, data);
    }
}
